<?php
/*
  [EWEISHOP] Copyright(C) 2017 Elinkint Inc.
  This is NOT a freeware, use is subject to license terms
   
  OfficialAccountBroadcasting.php 2018-05-25 09:50 likexin
   
*/

namespace common\library\wechat\officialaccount;

use common\library\wechat\WechatApi;
use common\component\wechat\Wechat;

class OfficialAccountBroadcasting extends WechatApi
{

    /**
     * 文本消息
     * @param string $text 消息内容
     * @param null $to 发送目标
     * @param array $to [openid1, openid2] 指定用户
     * @param integer $to 指定标签tagId
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function sendText(string $text, $to = null)
    {
        try {
            $result = self::getInstance()->broadcasting->sendText($text, $to);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 图片消息
     * @param string $mediaId 素材ID
     * @param null $to 发送目标
     * @param array $to [openid1, openid2] 指定用户
     * @param integer $to 指定标签tagId
     * @return array|bool|void
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function sendImage(string $mediaId, $to = null)
    {
        try {
            $result = self::getInstance()->broadcasting->sendImage($mediaId, $to);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 图文消息
     * @param string $mediaId 素材ID
     * @param null $to 发送目标
     * @param array $to [openid1, openid2] 指定用户
     * @param integer $to 指定标签tagId
     * @return array|bool|void
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function sendNews(string $mediaId, $to = null)
    {
        try {
            $result = self::getInstance()->broadcasting->sendNews($mediaId, $to);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 音频消息
     * @param string $mediaId 素材ID
     * @param null $to 发送目标
     * @param array $to [openid1, openid2] 指定用户
     * @param integer $to 指定标签tagId
     * @return array|bool|void
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function sendVoice(string $mediaId, $to = null)
    {
        try {
            $result = self::getInstance()->broadcasting->sendVoice($mediaId, $to);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 视频消息
     * @param string $mediaId 素材ID
     * @param null $to 发送目标
     * @param array $to [openid1, openid2] 指定用户
     * @param integer $to 指定标签tagId
     * @return array|bool|void
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function sendVideo(string $mediaId, $to = null)
    {
        try {
            $result = self::getInstance()->broadcasting->sendVideo($mediaId, $to);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 卡券消息
     * @param string $mediaId 素材ID
     * @param null $to 发送目标
     * @param array $to [openid1, openid2] 指定用户
     * @param integer $to 指定标签tagId
     * @return array|bool|void
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function sendCard(string $mediaId, $to = null)
    {
        try {
            $result = self::getInstance()->broadcasting->sendCard($mediaId, $to);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 预览文本消息
     * @param string $text 消息内容
     * @param string $openId 目标用户OPENID
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewText(string $text, string $openId)
    {
        try {
            $result = self::getInstance()->broadcasting->previewText($text, $openId);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 预览文本消息(微信号)
     * @param string $text 消息内容
     * @param string $wxname 目标用户微信号
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewTextByName(string $text, string $wxname)
    {
        $result = self::getInstance()->broadcasting->previewTextByName($text, $wxname);
        return Wechat::apiError($result);
    }

    /**
     * 预览图片消息
     * @param string $mediaId 素材ID
     * @param string $openId 目标用户OPENID
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewImage(string $mediaId, string $openId)
    {
        try {
            $result = self::getInstance()->broadcasting->previewImage($mediaId, $openId);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 预览图片消息(微信号)
     * @param string $mediaId 素材ID
     * @param string $wxname 目标用户微信号
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewImageByName(string $mediaId, string $wxname)
    {
        $result = self::getInstance()->broadcasting->previewImageByName($mediaId, $wxname);
        return Wechat::apiError($result);
    }

    /**
     * 预览图文消息
     * @param string $mediaId 素材ID
     * @param string $openId 目标用户OPENID
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewNews(string $mediaId, string $openId)
    {
        try {
            $result = self::getInstance()->broadcasting->previewNews($mediaId, $openId);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 预览图文消息(微信号)
     * @param string $mediaId 素材ID
     * @param string $wxname 目标用户微信号
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewNewsByName(string $mediaId, string $wxname)
    {
        $result = self::getInstance()->broadcasting->previewNewsByName($mediaId, $wxname);
        return Wechat::apiError($result);
    }

    /**
     * 预览音频消息
     * @param string $mediaId 素材ID
     * @param string $openId 目标用户OPENID
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewVoice(string $mediaId, string $openId)
    {
        try {
            $result = self::getInstance()->broadcasting->previewVoice($mediaId, $openId);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 预览音频消息(微信号)
     * @param string $mediaId 素材ID
     * @param string $wxname 目标用户微信号
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewVoiceByName(string $mediaId, string $wxname)
    {
        $result = self::getInstance()->broadcasting->previewVoiceByName($mediaId, $wxname);
        return Wechat::apiError($result);
    }

    /**
     * 预览视频消息
     * @param string $mediaId 素材ID
     * @param string $openId 目标用户OPENID
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewVideo(string $mediaId, string $openId)
    {
        try {
            $result = self::getInstance()->broadcasting->previewVideo($mediaId, $openId);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 预览视频消息(微信号)
     * @param string $mediaId 素材ID
     * @param string $wxname 目标用户微信号
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewVideoByName(string $mediaId, string $wxname)
    {
        $result = self::getInstance()->broadcasting->previewVideoByName($mediaId, $wxname);
        return Wechat::apiError($result);
    }

    /**
     * 预览卡券消息
     * @param string $mediaId 素材ID
     * @param string $openId 目标用户OPENID
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewCard(string $cardId, string $openId)
    {
        try {
            $result = self::getInstance()->broadcasting->previewCard($cardId, $openId);
        } catch (\Exception $result) {
        }
        return Wechat::apiError($result);
    }

    /**
     * 预览卡券消息(微信号)
     * @param string $mediaId 素材ID
     * @param string $wxname 目标用户微信号
     * @return mixed
     * @link https://www.easywechat.com/docs/master/zh-CN/official-account/broadcasting
     */
    public static function previewCardByName(string $cardId, string $wxname)
    {
        $result = self::getInstance()->broadcasting->previewCardByName($cardId, $wxname);
        return Wechat::apiError($result);
    }

    /**
     * 删除群发消息
     * @param string $msgId 消息ID
     * @return mixed
     */
    public static function delete(string $msgId)
    {
        $result = self::getInstance()->broadcasting->delete($msgId);
        return Wechat::apiError($result);
    }

    /**
     * 查询群发消息发送状态
     * @param string $msgId 消息ID
     * @return mixed
     */
    public static function status(string $msgId)
    {
        $result = self::getInstance()->broadcasting->status($msgId);
        return Wechat::apiError($result);
    }

}